//
//  BLCertIdentityVC.m
//  Byelone
//
//  Created by 乔小乔 on 2021/2/6.
//

#import "BLCertIdentityVC.h"

@interface BLCertIdentityVC ()
@property (unsafe_unretained, nonatomic) IBOutlet UILabel *labelStatus;
@property (unsafe_unretained, nonatomic) IBOutlet UITextField *textName;
@property (unsafe_unretained, nonatomic) IBOutlet UITextField *textCode;
@property (unsafe_unretained, nonatomic) IBOutlet UIButton *btnSubmit;
@property (unsafe_unretained, nonatomic) IBOutlet UILabel *labelTip;

@end

@implementation BLCertIdentityVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"身份认证";
    if (![self.dataModel.authStatus isEqualToString:@"0"]&&![NSString blIsBlankString:self.dataModel.authInfo]) {
        NSArray *array = [self.dataModel.authInfo componentsSeparatedByString:@","];
        if (array.count>=2) {
            self.textName.text = array[0];
            self.textCode.text = array[1];
            
            if (![self.dataModel.authStatus isEqualToString:@"3"]) {
                self.textName.userInteractionEnabled = NO;
                self.textCode.userInteractionEnabled = NO;
            }
            
            self.labelTip.hidden = YES;
            self.labelStatus.hidden = NO;
            self.labelStatus.text = [self getStatus:self.dataModel.authStatus];
        }
    }
}
- (NSString *)getStatus:(NSString *)status{
    NSDictionary *dict = @{@"0":@"待认证",@"1":@"认证中",@"2":@"认证通过",@"3":@"认证失败"};
    NSString *statusName = dict[status];
    return statusName;
}
- (void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    [self.btnSubmit setGradientBackgroundWithColors:@[[UIColor chColorWithHexString:@"#8881FD"],[UIColor chColorWithHexString:@"#6B71F5"]] locations:@[@(0.0f), @(1.0f)]  startPoint:CGPointMake(0, 0) endPoint:CGPointMake(1, 0)];
}
- (IBAction)clickSubmit:(id)sender {
    if ([self.dataModel.authStatus isEqualToString:@"1"]|| [self.dataModel.authStatus isEqualToString:@"2"]) {
        return;
    }
    NSDictionary *dict = @{@"idCard":self.textCode.text?:@"",@"realName":self.textName.text?:@""};
    [BLHttpTool postWithPath:BL_USER_SETIDCARD params:dict successBlock:^(NSDictionary * _Nonnull obj) {
        if (obj) {
            self.labelTip.hidden = YES;
            self.labelStatus.hidden = NO;
            self.labelStatus.text = obj[@"msg"];
            [[NSNotificationCenter defaultCenter]postNotificationName:Notification_login object:nil];
        }
    } failedBlock:^(NSURLSessionDataTask * _Nonnull data, NSError * _Nonnull error) {
        
    }];
}

@end
